<?php
namespace App\Models\PrizePayment;

class PrizePaymentRepository implements \App\Contracts\Repositories\PrizePaymentRepository
{
    public function insert($prizePayment)
    {
        return PrizePayment::insert($prizePayment);
    }

    public function create($prizePayment)
    {
        return PrizePayment::create($prizePayment);
    }

    public function modify($prizePayment, $conditions)
    {
        return PrizePayment::where($conditions)->update($prizePayment);
    }

    public function delete($conditions)
    {
        return PrizePayment::where($conditions)->delete();
    }

    public function findByConditionsPage($condition, $sortArray = [], $limit, $start)
    {
        $qb = PrizePayment::with('prize')->where($condition)->limit($limit)->skip($start);
        if (!empty($sortArray)) {
            foreach ($sortArray as $sort) {
                $qb = $qb->orderBy($sort[0], $sort[1]);
            }
        }

        return $qb->get();
    }

    public function countByConditions($condition)
    {
        $count = PrizePayment::with('prize')->where($condition)->count();

        return $count;
    }

    public function find($conditions)
    {
        return PrizePayment::where($conditions)->first();
    }
}
